package Operation;

import Book.Book;

import Book.Bookshelf;

import java.util.Scanner;

public class AddBook implements IOperation{
    @Override
    public void working(Bookshelf bookshelf) {
        //先进行判断书架是否已满
        if(bookshelf.bookShelfNumber == bookshelf.books.length){
            System.out.println("图书添加失败，书架已经满了!!!");
            return;
        }

        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入您所要添加的书的名称：");
        String name = scanner.nextLine();
        System.out.print("请输入您所要添加的书的作者：");
        String author = scanner.nextLine();
        System.out.print("请输入您所要添加的书的类型：");
        String type = scanner.nextLine();
        System.out.print("请输入您所要添加的书的价格：");
        int price = scanner.nextInt();

        Book newbook = new Book(name,author,price,type);

        //遍历书架上的所有图书
        for(int i = 0;i<bookshelf.bookShelfNumber;i++){
            Book book = bookshelf.books[i];
            if(book.equals(newbook)){
                System.out.println("对不起，已有该图书！！！");
                return;
            }
        }

        bookshelf.books[bookshelf.bookShelfNumber] = newbook;
        bookshelf.bookShelfNumber++;
        System.out.println("图书添加成功！！！");
    }
}
